<?php

/*
 * +----------------------------------------------------------------------
 * 作 者: songyb <1371626452@qq.com>
 * +----------------------------------------------------------------------
 * 创建日期：2015-06-16
 * +----------------------------------------------------------------------
 * 文件描述：教师研修网首页
 * +----------------------------------------------------------------------
 * 升级记录：
 * +----------------------------------------------------------------------
 */
class PublicAction extends Action
{

    /**
     * 根据学科编号获取相应年级编号(下拉菜单联动)
     */
    public function get_grade()
    {
        $data = getGradeBySubject($_REQUEST['subjectid']);
        if (! empty($data)) {
            $this->ajaxReturn($data, "查询成功", 1);
        } else {
            $this->ajaxReturn(null, "没有找到对应的字段", 0);
        }
    }

    /**
     * 获取省份列表
     * 
     * @return array
     */
    function get_province_list()
    {
        $model = new ProvinceModel();
        $data = $model->field("code, name")
            ->where("code in (select substring(area_code, 1, 2) from school)")
            ->select();
        return $data;
    }

    /**
     * 省市县联动时返回市州列表
     */
    public function get_city()
    {
        $model = new CityModel();
        $data = $model->field("code, name")
            ->where("province_code = '" . $_REQUEST['province_code'] . "'
					  	   and code in (select substring(area_code, 1, 4) from school)")
            ->select();
        
        if (! empty($data)) {
            $this->ajaxReturn($data, "查询成功", 1);
        } else {
            $this->ajaxReturn(null, "没有找到对应的字段", 0);
        }
    }

    /**
     * 省市县联动时返回县区列表
     */
    public function get_area()
    {
        $model = new AreaModel();
        $data = $model->field("code, name")
            ->where("city_code = '" . $_REQUEST['city_code'] . "'
					  	   and code in (select area_code from school)")
            ->select();
        if (! empty($data)) {
            $this->ajaxReturn($data, "查询成功", 1);
        } else {
            $this->ajaxReturn(null, "没有找到对应的字段", 0);
        }
    }

    /**
     * 省市县联动时返回学校列表
     */
    public function get_school()
    {
        $model = new SchoolModel();
        $data = $model->field("id code, name")
            ->where("area_code = '" . $_REQUEST['area_code'] . "'")
            ->select();
        if (! empty($data)) {
            $this->ajaxReturn($data, "查询成功", 1);
        } else {
            $this->ajaxReturn(null, "没有找到对应的字段" . $_REQUEST['area_code'], 0);
        }
    }
}
?>